*****************************************************************************************************************************************************************************************
****************************************************************************Turnout analyses*********************************************************************************************
*****************************************************************************************************************************************************************************************
cd "E:\workdata\704429\Projektfiles\Co-residence"
est clear
use analysis_out_data_all_pairs, clear

**Generate stacked datasæt**
gen id=_n
replace koen1 = koen1 - 1 
replace koen2 = koen2 - 1 

save temp_analysis1.dta, replace
foreach var in stemt residentialstability stemte_2009 pnr FOED_DAG koen  {
	rename `var'1 `var'3
	rename `var'2 `var'1
	rename `var'3 `var'2
}

append using temp_analysis1.dta

lab def koen 0 "male" 1 "female"
lab val koen1 koen
lab val koen2 koen

*****************************************************************************************************************************************************************************************
****************************************************************************FIGURE 5*****************************************************************************************************
*****************************************************************************************************************************************************************************************

preserve
collapse stemt1, by(month13) // Turnout depending on past turnout
scatter stemt1 month13, ///
 ytitle(Average  turnout) ///
 ylabel(0.40(0.05)0.80)  ///
 xtitle(Months from the election (30 day increments)) ///
 xline(0) mcolor(black) ///
 graphregion(color(white)) ///
 saving(move_in_graphs/figure1_temp1.gph, replace)  
 
scatter stemt1 month13 if month13>=-12 & month13<12, ///
 ytitle(Average  turnout) ///
 ylabel(0.40(0.05)0.80)  ///
 xtitle(Months from the election (30 day increments)) ///
 xline(0) mcolor(black) ///
 graphregion(color(white)) ///
 saving(move_in_graphs/figure1_temp2.gph, replace)  
restore 

graph combine move_in_graphs/figure1_temp1.gph move_in_graphs/figure1_temp2.gph, ///
 graphregion(color(white)) ///
 xsize(16) ysize(8) saving(move_in_graphs/figure1_vote.gph, replace)

graph export move_in_graphs/FigureS1.png, height(600) width(1200) replace
graph export output/FigureS1.png, height(600) width(1200) replace
